package org.chen.config;

import lombok.extern.slf4j.Slf4j;
import org.chen.service.CommentRuleMigrationService;
import org.chen.service.CommentTaskMigrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MigrationCommand implements CommandLineRunner {

    @Autowired
    private CommentTaskMigrationService migrationService;

    @Autowired
    private CommentRuleMigrationService migrateRule;

    @Override
    public void run(String... args) {
        if (args.length > 0) {
            log.info("开始执行数据迁移...");

            if (args[0].equals("task")) {
                // 执行迁移
                migrationService.migrateData();

                // 验证迁移结果
                migrationService.validateMigration();
            }else if (args[0].equals("rule")) {
                // 执行迁移
                migrateRule.migrateRule();

                // 验证迁移结果
                migrateRule.validateMigrationRule();
            }

        }
    }
}